package com.hunlian.makelove.dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.hunlian.makelove.R;
import com.hunlian.makelove.update.AppDownloadManager;

/**
 * Created by zealjiang on 2016/6/7 13:12.
 */
public class AcceptRefuseDialog {

    private AlertDialog dialog;

    public void showDialog(Activity context) {

        dialog = new AlertDialog.Builder(context).create();
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);

        View view = LayoutInflater.from(context).inflate(
                R.layout.dialog_accept_refuse, null);
        dialog.setView(view);
        try {
            dialog.show();
        } catch (Exception e) {
        }

        DisplayMetrics dm = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(dm);
        WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
        lp.width = (int) (dm.widthPixels * 0.86); // 设置宽度
        Window window = dialog.getWindow();
        window.setContentView(R.layout.dialog_accept_refuse);
        window.setAttributes(lp);

        Button btnAgree = (Button) window.findViewById(R.id.btn_agree);
        Button btnCancel = (Button) window.findViewById(R.id.btn_cancel);

        btnAgree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mAgreeBtnInf!=null){
                    mAgreeBtnInf.agree();
                }
            }
        });

        btnCancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

    }


    public AgreeBtnInf mAgreeBtnInf;
    public void setAgreeBtnInf(AgreeBtnInf agreeBtnInf){
        mAgreeBtnInf = agreeBtnInf;
    }
    public interface AgreeBtnInf{
        void agree();
    }
}
